package cn.zkcn.platform.modules.api.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.zkcn.platform.common.utils.R;
import cn.zkcn.platform.common.validator.Assert;
import cn.zkcn.platform.modules.api.annotation.AuthIgnore;
import cn.zkcn.platform.modules.sys.entity.SysUserEntity;
import cn.zkcn.platform.modules.sys.service.SysUserService;

/**
 * 注册
 */
@RestController
@RequestMapping("/api")
public class ApiRegisterController {
    @Autowired
    private SysUserService sysUserService;

    /**
     * 注册
     */
    @AuthIgnore
    @PostMapping("/register")
    public R register(String username, String password){
        Assert.isBlank(username, "用户名不能为空");
        Assert.isBlank(password, "密码不能为空");

        SysUserEntity user = new SysUserEntity();
        user.setUsername(username);
        user.setPassword(password);
        sysUserService.save(user);

        return R.ok();
    }
}
